package srcInterviewPrep;

public final class Counter
{
    /*
    static int bufferSize = 1000 * 60 * 60 * 24;
    
    DateTime lastIncrementTime;
    int[] buf;
    int curPos;
    
    public Counter()
    {
        buf = new int[bufferSize];
        lastIncrementTime = null;
        curPos = 0;
    }
    
    public void Increment()
    {
        DateTime curTime = DateTime.Now();
    
        if (lastIncrementTime == null)
        {
            lastIncrementTime = curTime;
        }
        
        int diffInMilis = DateTime.GetDifferenceInMilis(curTime, lastIncrementTime);
        
        if (diffInMilis == 0)
        {
            ++buf[curPos];
            return;
        }
                
        for (int i = 0; i < diffInMilis; ++i)
        {
            curPos = (curPos + 1) % bufferSize;
            buf[curPos] = 0;
        }
        
        ++buf[curPos];
    }
    
    public int GetQueriesInLastSecond()
    {
        return GetSumOfCounters(1000);
    }
    
    public int GetQueriesInLastMin()
    {
        return GetSumOfCounters(1000 * 60);
    }
    
    private int GetSumOfCounters(int numSamples)
    {
        int tempPos = GetPrevPos(curPos);
        int count = 0;
        
        for (int i = 0; i < numSamples; ++i)
        {
            count += buf[tempPos];
            tempPos = GetPrevPos(tempPos);
        }
        
        return count;
    }
    
    private int GetPrevPos(int pos)
    {
        if (pos == 0)
        {
            return bufferSize - 1;
        }
        
        return pos - 1;
    }
    
    */
}